package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration {
    //操作BookList类
    public void work(BookList bookList){
        System.out.println("新增图书");
        //有书这样的对象
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入书名");
        String name=scanner.nextLine();
        System.out.println("请输入作者");
        String author=scanner.nextLine();
        System.out.println("请输入价格");
        int price= scanner.nextInt();
        //多读一行
        scanner.nextLine();
        System.out.println("请输入类型");
        String type=scanner.nextLine();
        Book book=new Book(name,author,price,type);
        int currentsize= bookList.getUsedsize();
        //如果有这本书就放不进去 通过for循环遍历这本书
        for (int i = 0; i <currentsize ; i++) {
             Book book1=bookList.getBook(i);
             if (book1.getName().equals(name)){
                 System.out.println("书架有这本书添加不了");
                 return;//这个程序结束
             }
        }
        bookList.setBooks(currentsize,book);
        bookList.setUsedsize(currentsize+1);

    }
}
